//
//  BaseTabbarController.swift
//  SwitfTest
//
//  Created by runone02 on 2018/12/28.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

import UIKit

class BaseTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        initTabBar()
        // Do any additional setup after loading the view.
    }
    func initTabBar(){
        tabBar.barTintColor = UIColor.white
        let itemtitleArr = ["首页","专题","","生活服务","我的"]
        let icon_normal = [
            "icon_tabbar_subscription_active",
            "icon_tabbar_notification",
            "icon_tabBar" ,
            "icon_tabbar_home",
            "icon_tabbar_me" ]
        
        let icon_selected = [
            "tabbar_icon_home_selected",
            "icon_tabbar_notification_active",
            "icon_tabBar" ,
            "icon_tabbar_home_active",
            "icon_tabbar_me_active" ]
        
        let vcnamr = ["HomeViewController","FriendRootController","BaseViewController","AllViewController","MeViewController"]
        
        var viewControllerArr:Array = [UIViewController]()
        for i in 0..<vcnamr.count {
            let appname = Bundle.main.infoDictionary!["CFBundleExecutable"] as! String
            let cls  =  NSClassFromString(appname + "." + vcnamr[i]) as! BaseViewController.Type
            var vc:UIViewController!
            
            if i < vcnamr.count {
                vc = cls.init()
            }else{
                vc = UIStoryboard.init(name: "me", bundle: nil).instantiateViewController(withIdentifier: "me_stroryboar_identity")
            }
            
            let barItem = UITabBarItem (title: itemtitleArr[i], image: UIImage (named: icon_normal[i])?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage (named: icon_selected[i])?.withRenderingMode(.alwaysOriginal))
            barItem.tag = i
            
            if i == 2{
                barItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
            }
            barItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor.black], for: .selected)
            vc.tabBarItem = barItem
            vc.title = itemtitleArr[i]
            
            let navigationvc = BaseNavigationController(rootViewController:vc)
            viewControllerArr.append(navigationvc)

        }
        viewControllers = viewControllerArr
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
